import { reactive } from "vue";
import type { FormRules } from "element-plus";
// import { isPhone } from "@pureadmin/utils";

/** 自定义表单规则校验 */
export const formRules = reactive(<FormRules>{
  name: [{ required: true, message: "请输入姓名", trigger: "blur" }],
  password: [
    {
      required: true,
      validator: (rule, value, callback) => {
        if (value === "") {
          callback(new Error("请输入密码"));
        } else if (value.length < 6) {
          callback(new Error("密码长度不可小于6位"));
        } else {
          callback();
        }
      },
      trigger: "blur"
    }
  ],
  phone: [{ required: true, message: "请输入账号", trigger: "blur" }]
  // roleIdList: [{ required: true, message: "请选择角色", trigger: "blur" }]
  // phone: [
  //   {
  //     required: true,
  //     validator: (rule, value, callback) => {
  //       if (value === "") {
  //         callback(new Error("请输入手机号"));
  //       } else if (!isPhone(value)) {
  //         callback(new Error("请输入正确的手机号码格式"));
  //       } else {
  //         callback();
  //       }
  //     },
  //     trigger: "blur"
  //     // trigger: "click" // 如果想在点击确定按钮时触发这个校验，trigger 设置成 click 即可
  //   }
  // ]
});
